<!DOCTYPE html>
<html lang="en" style="background:#fff;">
<head>
	<base href="${basePath}">
	<#include "common/top.html"/>
	<style>
		.layui-form-item .layui-form-checkbox[lay-skin=primary] {
			margin-top: 0px;
		}
	</style>
</head>
<body style="background:#fff;">

<form class="layui-form layui-form-pamel" style="display: inline-block;" name="form1" id="form1" method="post">
<div style="width: 100%;padding-bottom: 20px;">
	<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
		<ul class="layui-tab-title">
			<li class="layui-this">基本信息</li>
			<li>字段信息</li>
			<li>生成信息</li>
		</ul>
		<div class="layui-tab-content" style="height: 100px;">
			<!-- 基本信息 -->
			<div class="layui-tab-item layui-show">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">表名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="tableName" id="tableName" value="${table.tableName}" placeholder="请输入表名称" class="layui-input">
							<input type="hidden" name="tableId" id="tableId" value="${table.tableId}">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">表描述：</label>
						<div class="layui-input-inline">
							<input type="text" name="tableComment" id="tableComment" value="${table.tableComment}" placeholder="请输入表描述" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">实体类名称：</label>
						<div class="layui-input-inline">
							<input type="text" name="className" id="className" value="${table.className}" placeholder="请输入实体类名称" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">作者：</label>
						<div class="layui-input-inline">
							<input type="text" name="functionAuthor" id="functionAuthor" value="${table.functionAuthor}" placeholder="请输入作者" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">备注：</label>
						<div class="layui-input-inline">


							<input type="text" name="remark" id="remark" value="${table.remark}" placeholder="请输入备注" class="layui-input">
						</div>
					</div>
				</div>
			</div>
			<div class="layui-tab-item">
				<div class="layui-form-item">
					<table id="table-column" class="layui-table" lay-filter="table-column"></table>
				</div>
			</div>
			<div class="layui-tab-item">
				<div class="layui-form-item">
					<div class="layui-inline">
						<label class="layui-form-label">生成模板：</label>
						<div class="layui-input-inline">
							<select id="tplCategory" name="tplCategory" lay-filter="tplCategory">
								<option value="crud">单表（增删改查）</option>
								<option value="tree">树表（增删改查）</option>
							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">生成包路径：</label>
						<div class="layui-input-inline">
							<input type="text" name="packageName" id="packageName" value="${table.packageName}" placeholder="请输入生成包路径" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">生成模块名：</label>
						<div class="layui-input-inline">
							<input type="text" name="moduleName" id="moduleName" value="${table.moduleName}" placeholder="请输入生成模块名" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">生成业务名：</label>
						<div class="layui-input-inline">
							<input type="text" name="businessName" id="businessName" value="${table.businessName}" placeholder="请输入生成业务名(project后的包名，)" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label">生成功能名：</label>
						<div class="layui-input-inline">
							<input type="text" name="functionName" id="functionName" value="${table.functionName}" placeholder="请输入生成功能名" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
							<input type="text" value="URL地址：/生成模块名/生成业务名" class="layui-input" readonly style="width: 250px;">
					</div>
					<div class="layui-inline">
						<input type="text" value="包：生成包路径/生成业务名" class="layui-input" readonly style="width: 250px;"
						ls
						>
					</div>
				</div>
			</div>
		</div>
	</div>

</div>
</form>
	<!--<div class="layui-form-item">-->
		<!--<div class="layui-inline">-->
			<!--<div class="layui-input-inline">-->
				<!--<input type="button" value="保存" onclick="submitHandler();" class="layui-btn layui-btn-red mr10"/>-->
			<!--</div>-->
		<!--</div>-->
		<!--<div class="layui-inline">-->
			<!--<div class="layui-input-inline">-->
				<!--<a href="javascript:history.go(-1)" class="layui-btn-tan">-->
					<!--<i class="layui-icon">&#xe65c;</i> 返回-->
				<!--</a>-->
			<!--</div>-->
		<!--</div>-->
	<!--</div>-->
</body>
</html>
<#include "/common/dictselect.html">

<script type="text/javascript">
    var formTable;
    var table;
    var form;

    layui.config({
        base: "./plugins/layui/lay/modules/"
    }).extend({
        optimizeSelectOption: "optimizeSelectOption",//引入js
    }).use(['layer','element', 'table','form','optimizeSelectOption'], function(){
        var  $ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, element = layui.element;
        var pathTemp = layui.cache.modules['optimizeSelectOption'] || '';
        var filePath = pathTemp.substr(0, pathTemp.lastIndexOf('/'));
        // 引入css
        layui.link(filePath + '../../../css/modules/optimizeSelectOption.css');
    });

    layui.use(['form','table','element'], function(){
        form = layui.form;
        table = layui.table;
        var element = layui.element;
        form.render();
        formTable = table.render({
            elem: '#table-column',
            url:'${basePath}tool/column/list',
            method: 'post',
            where:{ti:new Date().getTime(),tableId:'${table.tableId}'},
            request: {
                pageName: 'currentPage' //页码的参数名称，默认：page
                ,limitName: 'showCount' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'status' //数据状态的字段名称，默认：code
                ,statusCode: true //成功的状态码，默认：0
                ,msgName: 'msg' //状态信息的字段名称，默认：msg
                ,countName: 'totalResult' //数据总数的字段名称，默认：count
                ,dataName: 't' //数据列表的字段名称，默认：data
            },
            cols: [[
                {type:'numbers', title: '序号',width:50}
                ,{field: 'columnName', title: '字段列名'}
                ,{field: 'columnComment',title: '字段描述',templet: function (d) {
                        var columnId = "<input type='hidden' name='columns["+(d.LAY_INDEX-1)+"].columnId' value='"+d.columnId+"' class='layui-input'>";
                        var html = columnId + "<input type='text' name='columns["+(d.LAY_INDEX-1)+"].columnComment' value='"+d.columnComment+"' class='layui-input'>";
					return html;
				}}
                ,{field: 'columnType',title: '物理类型',width:150}
                ,{field: 'javaType', title: 'Java类型',templet: function (d) {
                	return javaTypeMacro((d.LAY_INDEX-1),d.javaType);
                }}
                ,{field: 'javaField', title: 'Java属性',templet: function (d) {
					var html = "<input type='text' name='columns["+(d.LAY_INDEX-1)+"].javaField' value='"+d.javaField+"' class='layui-input'>";
					return html;
				}}
                ,{field: 'isInsert', title: '插入',width:70,templet: function (d) {
					var isCheck = d.isInsert == 1 ? 'checked' : '';
					var html = "<input type='checkbox' name='columns["+(d.LAY_INDEX-1)+"].isInsert' value='1' " + isCheck + " lay-skin='primary'>";
					return html;
				}}
                ,{field: 'isEdit', title: '编辑',width:70,templet: function (d) {
					var isCheck = d.isEdit == 1 ? 'checked' : '';
					var html = "<input type='checkbox' name='columns["+(d.LAY_INDEX-1)+"].isEdit' value='1' " + isCheck + " lay-skin='primary'>";
					return html;
				}}
                ,{field: 'isList', title: '列表',width:70,templet: function (d) {
					var isCheck = d.isList == 1 ? 'checked' : '';
					var html = "<input type='checkbox' name='columns["+(d.LAY_INDEX-1)+"].isList' value='1' " + isCheck + " lay-skin='primary'>";
					return html;
				}}
                ,{field: 'isQuery', title: '查询',width:70,templet: function (d) {
                        var isCheck = d.isQuery == 1 ? 'checked' : '';
                        var html = "<input type='checkbox' name='columns["+(d.LAY_INDEX-1)+"].isQuery' value='1' " + isCheck + " lay-skin='primary'>";
                        return html;
                 }}
                ,{field: 'queryType', title: '查询方式',width:120,templet: function (d) {
                        return queryTypeMacro((d.LAY_INDEX-1),d.queryType);
				}}

                ,{field: 'isRequired', title: '必填',width:70,templet: function (d) {
					var isCheck = d.isRequired == 1 ? 'checked' : '';
					var html = "<input type='checkbox' name='columns["+(d.LAY_INDEX-1)+"].isRequired' value='1' " + isCheck + " lay-skin='primary'>";
					return html;
				}}
                ,{field: 'htmlType', title: '显示类型',templet: function (d) {
                        return htmlTypeMacro((d.LAY_INDEX-1),d.htmlType);
				}}
                //,{field: 'dictType', title: '字典类型',width:90}
            ]],
            page: true
        });

        table.on('tool(simple-table)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){

            }
        });
    });
    function javaTypeMacro(index,javaType){
        var html = '<select id="columns['+index+'].javaType" name="columns['+index+'].javaType" lay-filter="columns['+index+'].javaType">';
        if(javaType=="Long"){
            html += '<option value="Long" selected >Long</option>';
        }else{
            html += '<option value="Long">Long</option>';
        }
        if(javaType=="String"){
            html += '<option value="String" selected>String</option>';
        }else{
            html += '<option value="String">String</option>';
        }
        if(javaType=="Integer"){
            html += '<option value="Integer" selected>Integer</option>';
        }else{
            html += '<option value="Integer">Integer</option>';
        }
        if(javaType=="Double"){
            html += '<option value="Double" selected>Double</option>';
        }else{
            html += '<option value="Double">Double</option>';
        }
        if(javaType=="BigDecimal"){
            html += '<option value="BigDecimal" selected>BigDecimal</option>';
        }else{
            html += '<option value="BigDecimal">BigDecimal</option>';
        }
        if(javaType=="Date"){
            html += '<option value="Date" selected>Date</option>';
        }else{
            html += '<option value="Date">Date</option>';
        }
        html += '</select>';

        return html;
    }

    function queryTypeMacro(index,queryType){
        var html = '<select id="columns['+index+'].queryType" name="columns['+index+'].queryType" lay-filter="columns['+index+'].queryType">';
        if(queryType=="Long"){
            html += '<option value="EQ" selected >=</option>';
        }else{
            html += '<option value="EQ">=</option>';
        }
        if(queryType=="NE"){
            html += '<option value="NE" selected>!=</option>';
        }else{
            html += '<option value="NE">!=</option>';
        }
        if(queryType=="GT"){
            html += '<option value="GT" selected>></option>';
        }else{
            html += '<option value="GT">></option>';
        }
        if(queryType=="GTE"){
            html += '<option value="GTE" selected>>=</option>';
        }else{
            html += '<option value="GTE">>=</option>';
        }
        if(queryType=="LT"){
            html += '<option value="LT" selected><<</option>';
        }else{
            html += '<option value="LT"><<</option>';
        }
        if(queryType=="LTE"){
            html += '<option value="LTE" selected><=</option>';
        }else{
            html += '<option value="LTE"><=</option>';
        }
        if(queryType=="LIKE"){
            html += '<option value="LIKE" selected>Like</option>';
        }else{
            html += '<option value="LIKE">Like</option>';
        }
        if(queryType=="BETWEEN"){
            html += '<option value="BETWEEN" selected>Between</option>';
        }else{
            html += '<option value="BETWEEN">Between</option>';
        }
        html += '</select>';

        return html;
    }

    function htmlTypeMacro(index,htmlType){
        var html = '<select id="columns['+index+'].htmlType" name="columns['+index+'].htmlType" lay-filter="columns['+index+'].htmlType">';
        if(htmlType=="input"){
            html += '<option value="input" selected >文本框</option>';
        }else{
            html += '<option value="input">文本框</option>';
        }
        if(htmlType=="textarea"){
            html += '<option value="textarea" selected>文本域</option>';
        }else{
            html += '<option value="textarea">文本域</option>';
        }
        if(htmlType=="select"){
            html += '<option value="select" selected>下拉框</option>';
        }else{
            html += '<option value="select">下拉框</option>';
        }
        if(htmlType=="radio"){
            html += '<option value="radio" selected>单选框</option>';
        }else{
            html += '<option value="radio">单选框</option>';
        }
        if(htmlType=="checkbox"){
            html += '<option value="checkbox" selected>复选框</option>';
        }else{
            html += '<option value="checkbox">复选框</option>';
        }
        if(htmlType=="datetime"){
            html += '<option value="datetime" selected>日期控件</option>';
        }else{
            html += '<option value="datetime">日期控件</option>';
        }
        html += '</select>';

        return html;
    }

    function submitHandler() {
        $.operate.post('${basePath}tool/edit', $("#form1").serializeArray(), function(result) {
            if (result.status == true) {
                layer.alert(result.msg,function(index){
                    var index1 = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index1);
                    layer.close(index);
                });
            }else{
                parent.layer.alert(result.msg);
            }
        });
    }
</script>
